home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Symantec Versions / C09 App-QuickTime / P01 Film Edit / Generic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-05  |  7.2 KB  |  335 lines  |  [TEXT/KAHL]

  1. //____________________________________________________________
  2. //    Generic.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include <Movies.h>
  13.   
  14. #include "Defines.h" 
  15. #include "DataTypes.h"
  16. #include "Globals.h"
  17. #include "Initialize.h"
  18. #include "WindRecordAccess.h"
  19. #include "MovieUtilities.h"
  20. #include "AppleMenu.h"
  21. #include "FileMenu.h"
  22. #include "EditMenu.h"
  23. #include "Generic.h"
  24.  
  25.  
  26. //____________________________________________________________
  27.  
  28. void  main( void )
  29. {
  30.    InitializeAllToolboxes();
  31.  
  32.    SetUpMenuBar();
  33.    
  34.    EventLoop();
  35. }
  36.  
  37.  
  38. //____________________________________________________________
  39.  
  40. void  EventLoop( void )
  41.    EventRecord  theEvent;      
  42.    Boolean      isControllerEvent;
  43.  
  44.    while ( gDone == false )
  45.    {      
  46.       WaitNextEvent( everyEvent, &theEvent, 0, nil );
  47.  
  48.       AdjustAllMenus();
  49.       
  50.       isControllerEvent = UpdateAllOpenMovies( theEvent );
  51.       
  52.       if ( isControllerEvent == false )
  53.       {
  54.          switch ( theEvent.what )
  55.          {
  56.             case activateEvt:
  57.                HandleActivateEvent( theEvent );
  58.                break;
  59.                   
  60.             case updateEvt:
  61.                HandleUpdateEvent( theEvent );
  62.                break;
  63.  
  64.             case keyDown:
  65.                HandleKeyDownEvent( theEvent );
  66.                break;
  67.             
  68.             case mouseDown:
  69.                HandleMouseDownEvent( theEvent );
  70.                break;
  71.          }
  72.       }
  73.    }
  74. }
  75.  
  76.  
  77. //____________________________________________________________
  78.  
  79. void  AdjustAllMenus( void )
  80. {
  81.    WindowPtr        theWindow;
  82.    MovieController  theController;
  83.    MenuHandle       theMenu;
  84.    
  85.    theWindow = FrontWindow();
  86.    
  87.    if ( theWindow == nil )
  88.    {
  89.       theMenu = GetMHandle( mFile );
  90.       DisableItem( theMenu, iClose );
  91.       DisableItem( theMenu, iSave );
  92.       DisableItem( theMenu, iSaveAs );
  93.  
  94.       theMenu = GetMHandle( mEdit );
  95.       DisableItem( theMenu, iUndo );
  96.       DisableItem( theMenu, iCut );
  97.       DisableItem( theMenu, iCopy );
  98.       DisableItem( theMenu, iPaste );
  99.       DisableItem( theMenu, iClear );
  100.       DisableItem( theMenu, iSelectAll );      
  101.    }
  102.    else
  103.    {
  104.       theMenu = GetMHandle( mFile );
  105.       EnableItem( theMenu, iClose );
  106.       EnableItem( theMenu, iSave );
  107.       EnableItem( theMenu, iSaveAs );
  108.  
  109.       theMenu = GetMenuHandle( mEdit );
  110.       if ( GetWindowType( theWindow ) == kMovieWindowType )
  111.       {
  112.          theController = GetWindowController( theWindow );
  113.          MCSetUpEditMenu( theController, 0, theMenu );
  114.          EnableItem( theMenu, iSelectAll );
  115.       }
  116.       else
  117.       {
  118.          EnableItem( theMenu, iUndo );
  119.          EnableItem( theMenu, iCut );
  120.          EnableItem( theMenu, iCopy );
  121.          EnableItem( theMenu, iPaste );
  122.          EnableItem( theMenu, iClear );
  123.          EnableItem( theMenu, iSelectAll );      
  124.       }   
  125.    }
  126. }
  127.  
  128.  
  129. //____________________________________________________________
  130.  
  131. void  HandleActivateEvent( EventRecord theEvent )
  132. {
  133.    WindowPtr        theWindow;
  134.    Boolean          isActivateEvent;
  135.    MovieController  theController;
  136.    
  137.    theWindow = (WindowPtr)theEvent.message;
  138.    SetPort( theWindow );
  139.    isActivateEvent = ( theEvent.modifiers & activeFlag ) != 0;
  140.  
  141.    if ( GetWindowType( theWindow ) == kMovieWindowType )
  142.    {
  143.       theController = GetWindowController( theWindow );
  144.       MCActivate( theController, theWindow, isActivateEvent );
  145.    }
  146. }
  147.  
  148.  
  149. //____________________________________________________________
  150.  
  151. void  HandleUpdateEvent( EventRecord theEvent )
  152. {
  153.    WindowPtr  theWindow;
  154.    
  155.    theWindow = (WindowPtr)theEvent.message;
  156.    BeginUpdate( theWindow );
  157.       EraseRect( &(theWindow->portRect) );
  158. //    update "nonQuickTime" windows here
  159.    EndUpdate( theWindow );
  160. }
  161.  
  162.  
  163. //____________________________________________________________
  164.  
  165. void  HandleKeyDownEvent( EventRecord theEvent )
  166. {
  167.    short  theChar; 
  168.    long   theMenuAndItem;
  169.    
  170.    theChar = theEvent.message & charCodeMask;
  171.    
  172.    if ( ( theEvent.modifiers & cmdKey ) != 0 )
  173.    {
  174.       if ( theEvent.what != autoKey ) 
  175.       {
  176.          theMenuAndItem = MenuKey( theChar );
  177.          HandleMenuChoice( theMenuAndItem );
  178.       }
  179.    }
  180. }
  181.  
  182.  
  183. //____________________________________________________________
  184.  
  185. void  HandleMouseDownEvent( EventRecord theEvent )
  186. {
  187.    WindowPtr  theWindow;
  188.    short      thePart;
  189.    long       theMenuAndItem;
  190.    
  191.    thePart = FindWindow( theEvent.where, &theWindow );
  192.  
  193.    switch ( thePart )
  194.    {
  195.       case inMenuBar:
  196.          theMenuAndItem = MenuSelect( theEvent.where );
  197.          HandleMenuChoice( theMenuAndItem );              
  198.          break;
  199.          
  200.       case inGoAway: 
  201.          if ( TrackGoAway( theWindow, theEvent.where ) )
  202.          {
  203.             if ( GetWindowType( theWindow ) != kMovieWindowType )
  204.             {
  205.                DisposeWindow( theWindow );   
  206.                --gWindowCount;
  207.             }
  208.             else
  209.                CloseMovieAndFile( theWindow );
  210.          }
  211.          break;
  212.  
  213.       case inDrag: 
  214.          DragWindow( theWindow, theEvent.where, &qd.screenBits.bounds );
  215.          break;
  216.  
  217.       case inContent:
  218.          SelectWindow( theWindow );
  219.          break;
  220.    }
  221. }
  222.  
  223.  
  224. //____________________________________________________________
  225.  
  226. void  HandleMenuChoice( long  theMenuAndItem ) 
  227. {
  228.    short  theMenu;
  229.    short  theMenuItem;
  230.     
  231.    if ( theMenuAndItem != 0 )
  232.    {
  233.       theMenu = HiWord( theMenuAndItem ); 
  234.       theMenuItem = LoWord( theMenuAndItem ); 
  235.  
  236.       switch ( theMenu )
  237.       {
  238.          case mApple:
  239.             HandleAppleChoice( theMenuItem );
  240.             break;
  241.                 
  242.          case mFile: 
  243.             HandleFileChoice( theMenuItem );
  244.             break;
  245.             
  246.          case mEdit: 
  247.             HandleEditChoice( theMenuItem );
  248.             break;
  249.       }
  250.       HiliteMenu(0);     
  251.    }
  252. }
  253.  
  254.  
  255. //____________________________________________________________
  256.  
  257. void  HandleAppleChoice( short theMenuItem )
  258. {
  259.    switch ( theMenuItem )
  260.    {
  261.       case iAbout:
  262.          HandleAppleMenuAboutItem();
  263.          break;
  264.          
  265.       default:
  266.          HandleAppleMenuDefaultItem( theMenuItem );
  267.          break;
  268.    }
  269. }
  270.  
  271.  
  272. //____________________________________________________________
  273.  
  274. void  HandleFileChoice( short theMenuItem )
  275. {
  276.    switch ( theMenuItem )
  277.    {
  278.       case iOpen:
  279.          HandleFileMenuOpenItem();
  280.          break;
  281.          
  282.       case iClose:
  283.          HandleFileMenuCloseItem();
  284.          break;
  285.  
  286.       case iSave:
  287.          HandleFileMenuSaveItem();
  288.          break;
  289.  
  290.       case iSaveAs:
  291.          HandleFileMenuSaveAsItem();
  292.          break;
  293.  
  294.       case iQuit:
  295.          HandleFileMenuQuitItem();
  296.          break;
  297.    }
  298. }
  299.  
  300.  
  301. //____________________________________________________________
  302.  
  303. void  HandleEditChoice( short theMenuItem )
  304. {
  305.    switch ( theMenuItem )
  306.    {
  307.       case iUndo:
  308.          HandleEditMenuUndoItem();
  309.          break;
  310.  
  311.       case iCut:
  312.          HandleEditMenuCutItem();
  313.          break;
  314.  
  315.       case iCopy:
  316.          HandleEditMenuCopyItem();
  317.          break;
  318.  
  319.       case iPaste:
  320.          HandleEditMenuPasteItem();
  321.          break;
  322.  
  323.       case iClear:
  324.          HandleEditMenuClearItem();
  325.          break;
  326.          
  327.       case iSelectAll:   
  328.          HandleEditMenuSelectAllItem();
  329.          break;
  330.    }
  331. }
  332.  
  333.  
  334.